package com.tangyee.person.activity;

import android.content.ContentValues;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;

import com.tangyee.person.db.PersonInfo;
import com.tangyee.R;
import com.tangyee.person.HeadPicture;
import com.tangyee.person.db.BaseInfo;
import com.tangyee.person.db.PersonInfo;
import com.tangyee.person.dialogfragment.NewNameDialogFragment;

import org.litepal.LitePal;
import org.litepal.tablemanager.Connector;

import java.util.List;

public class ChangeUserNameActivity extends AppCompatActivity implements View.OnClickListener,NewNameDialogFragment.DialogListener{
    private PersonInfo personInfo;
    private EditText et;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_person_change_name);
        findViewById(R.id.backToperson3).setOnClickListener(this);
        findViewById(R.id.saveToPerson).setOnClickListener(this);
        personInfo= LitePal.findFirst(PersonInfo.class);
        et=(EditText)findViewById(R.id.change_nickname_userinfo);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.backToperson3:
                Intent intent1 = new Intent(ChangeUserNameActivity.this,HeadPicture.class);
                startActivity(intent1);
                finish();
                break;
            case R.id.saveToPerson:
                //保存
                if(et.getText().toString().equals("")==true){
                    DialogFragment dialogFragment = new NewNameDialogFragment();
                    dialogFragment.show(getSupportFragmentManager(), "");
                }else {
                    personInfo.setName(et.getText().toString());
                    personInfo.update(1);
                    Intent intent = new Intent(ChangeUserNameActivity.this,HeadPicture.class);
                    startActivity(intent);
                    finish();
                }
                break;
        }
    }

    @Override
    public void onDialogPositiveClick(DialogFragment dialogFragment) {

    }

    @Override
    public void onDialogNegativeClick(DialogFragment dialogFragment) {

    }
}
